﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="../lib/css/layui.css" rel="stylesheet" type="text/css" />
    <script src="../lib/layui.js"></script>
</head>
<body>


    <blockquote class="layui-elem-quote"> 表单form - 初始化</blockquote>

    <form class="layui-form" lay-filter="curForm">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block"><input class="layui-input" name="UserName" /></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block"><input class="layui-input" name="CellPhone" /></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">下拉是否</label>
            <div class="layui-input-block">
                <select name="YesNO">
                    <option value="">-请选择-</option>
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">Radio是否</label>
            <div class="layui-input-block">
                <input type="checkbox" name="AiHao[write]" title="写作">
                <input type="checkbox" name="AiHao[read]" title="阅读">
                <input type="checkbox" name="AiHao[dai]" title="发呆">
            </div>
        </div>
    </form>


    <pre class="layui-code" lay-title="html代码">
/*
    说明:
*/
  var jsonData = {
            "UserName": "张三",
            "CellPhone": "13862740967",
            "YesNO": "0",
            "AiHao[dai]": true,
            "AiHao[read]": true
        };
关于CheckBoxName是同名的问题进行处理
</pre>





    <script>
        layui.code({ encode: true });

        var jsonData = {
            "UserName": "张三",
            "CellPhone": "13862740967",
            "YesNO": "0",
            "AiHao[dai]": true,
            "AiHao[read]": true
        };



        layui.form.val("curForm", jsonData);


        //赋值完成后进行重新的渲染
        layui.form.render();

    </script>
</body>
</html>